let scene, camera, renderer;

const init = () => {
    //场景
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0x000000);
    //渲染器
    renderer = new THREE.WebGLRenderer({
        antialias: true
    });
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);
    //相机
    const aspect = window.innerWidth / window.innerHeight
    camera = new THREE.PerspectiveCamera(60, aspect, 0.01, 5000);
    camera.rotation.y = (90 / 180) * Math.PI
    camera.position.set(5, 0, 0);
    //相机轨道控制器
    const controls = new THREE.OrbitControls(camera, renderer.domElement);
    controls.update()
    // controls.addEventListener("change", renderer)
    //环境光
    const ambientLight = new THREE.AmbientLight('#FFFAFA', 30)
    scene.add(ambientLight)
    //加载器
    const loader = new THREE.GLTFLoader();
    loader.load('assest/scene.gltf', res => {
    scene.add(res.scene);
        //渲染一帧
        // renderer.render(scene,camera);
        //动画渲染
        animate()
    })
}
//监听鼠标拖拽事件，循环渲染场景和模型
const animate = () => {
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
}

init()